<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/19
 * Time: 18:47
 */

namespace app\api\controller;


use think\Db;
use think\Request;

class UserBase
{
    //protected $wx_openid = null;

    protected $userId = null;

    protected $api_token = null;

    protected $status = null;
    protected $info = null;
    protected $user;
    protected $param;
    public function __construct()
    {
        //        $this->userId = input('userId');//用户的id
        //        $this->wx_openid = input('wx_openid');//微信获取到返回给前端的wx_openid

        //$this->api_token = 1;
        $this->api_token = Request::instance()->header('authorization');
        if (empty($this->api_token)) {
            return apiError("请授权登录", -100);
        }
        $user = Db::table('sms_mk_users')
            //            ->where('id',$this->userId)
            ->where('api_token', '=', $this->api_token)
            //            ->where('wx_openid',$this->wx_openid)
            ->find();
        if (empty($user)) {
            return apiError("该用户不存在", 403);
        }
        $this->user = $user;
        $this->userId = $user['id'];
        $this->param = input();
        unset($this->param['api_token']);
        $this->param['sms_users_id'] = $this->userId;
    }
}
